package com.hongye.consult.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.hongye.common.utils.ResponseResult;
import com.hongye.consult.entity.ConsultEntity;
import com.hongye.consult.entity.HouseEntity;
import com.hongye.consult.service.ConsultService;
import com.hongye.consult.vo.DetailVo;
import com.hongye.consult.vo.FindRentingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 *
 * @author hxy
 * @email 3199037134@qq.com
 * @date 2022-04-26 18:42:18
 */
@RestController
@RequestMapping("consult/consult")
public class ConsultController {

    @Autowired
    ConsultService consultService;



    /**
     * 查找主题咨询  形成链接
     * 前 5 调
     * 根据时间 倒叙排序
     * 进行时间区间进行查询
     * @return
     */
    @RequestMapping("findSubjectConsultation")
    public ResponseResult findSubjectConsultation(){
        //进行去查询数据
        List<ConsultEntity> consultEntityList=consultService.findSubjectConsultation();
        //判断
        if(consultEntityList!=null){
            return  new ResponseResult(true,200, "楼市咨询",consultEntityList);
        }
        return  new ResponseResult(false,500,"没有最新的楼市咨询");
    }


    /**
     * 查找主题咨询
     * 点击跳入详细页面
     * 获取到 楼市咨询的楼的信息 id 进行查询
     * @param houseId
     * @return
     */
    @RequestMapping("findConsultDetail")
    public ResponseResult findConsultDetail(@RequestParam("houseId") Integer houseId){
        //点击进行查询文章
        List<HouseEntity> houseEntities=consultService.findConsultDetail(houseId);
        //判断
        if(houseEntities!=null){
            return  new ResponseResult(true,200, "楼市咨询详细",houseEntities);
        }
        return  new ResponseResult(false,500,"楼市咨询详细");
    }

    /**
     * 点击更多
     * 查询咨询频道的列表
     * 双表联查的 展示 图片 和  房屋信息
     */
    @RequestMapping("findAllConsult")
    public ResponseResult findAllConsult(){
        //点击进行查询文章
        List<DetailVo> houseEntities=consultService.findAllConsult();
        //判断
        if(houseEntities!=null){
            return  new ResponseResult(true,200, "资讯频道",houseEntities);
        }
        return  new ResponseResult(false,500,"网络原因更新不过来");
    }

    /**
     * 租房列表 查询条件
     * @param currPage
     * @param pageSize
     * @param findRentingVo
     * @return
     */
    @RequestMapping("findRentingList")
    public ResponseResult findRentingList(@RequestParam("currPage") Integer currPage,
                                          @RequestParam("pageSize") Integer pageSize,
                                          @RequestBody FindRentingVo findRentingVo
                                          ){
        //租房列表
        PageInfo<HouseEntity> houseEntities=consultService.findRentingList(currPage,pageSize,findRentingVo);
        //判断
        if(houseEntities!=null){
            return  new ResponseResult(true,200, "租房",houseEntities);
        }
        return  new ResponseResult(false,500,"网络原因更新不过来");
    }


    //地图找房-租房









}
